package com.j.lemon.learn.basic.controller;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Controller
@RequestMapping(value = "/api")
public class UserController implements ApplicationContextAware,InitializingBean{

    private ApplicationContext applicationContext;


    UserController(){
        System.out.println("init");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("after");
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext=applicationContext;
        System.out.println("set applicationContext");
    }

    @RequestMapping(value = "/hello")
    public void hello(){
        String displayName = applicationContext.getDisplayName();
        String applicationName = applicationContext.getApplicationName();
        long startupDate = applicationContext.getStartupDate();
        System.out.println(displayName);
        System.out.println(applicationName);
        System.out.println(startupDate);

        ApplicationContext parent = applicationContext.getParent();
        String displayName1 = parent.getDisplayName();
        String applicationName1 = parent.getApplicationName();
        long startupDate1 = parent.getStartupDate();

        System.out.println(displayName1);
        System.out.println(applicationName1);
        System.out.println(startupDate1);
    }


}

